package com.kancy.demo.delay.queue.redis.controller;

import com.kancy.demo.delay.queue.redis.entity.User;
import com.kancy.demo.delay.queue.redis.message.PollingDelayMessage;
import com.kancy.delay.queue.redis.service.DelayQueueClient;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * TestController
 * <p>
 *
 * @author: kancy
 * @date: 2020/3/4 10:29
 **/
@RequiredArgsConstructor
@RestController
@RequestMapping("/test")
public class TestController {

    private final DelayQueueClient delayQueueClient;

    /**
     * 发送延迟消息
     * @param topic
     * @param delay
     * @return
     */
    @GetMapping("/delay/send")
    public String sendTestDelayMessage(String topic, long delay){
        // 定义消息体
        User user = new User("tom", 25);
        // 定义延时消息
        PollingDelayMessage message = new PollingDelayMessage(topic, user, delay);
        message.setName("polling");
        // 发送延时消息到redis延时队列
        delayQueueClient.sendMessage(message);
        return "ok";
    }

}
